import Vue from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';
import Element from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import 'animate.css';
import 'video.js/dist/video-js.css';
import { showTips } from '@/utils/showTips';

Vue.use(Element);

// style
import '@/assets/theme/reset.css';
import './assets/theme/font.css';

// utils
import utils from './utils/utils.js';
Vue.prototype.$utils = utils;

// filter
import * as filters from './utils/filter';
require('./utils/showTips');
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key]);
});

// 指令
Vue.directive('showTips', showTips);

// api
import api from '@/api';
Vue.prototype.$api = api;

Vue.config.productionTip = false;

router.beforeEach((to, from, next) => {
  const token = localStorage.getItem('token');
  if (to.path !== '/login') {
    if (token) {
      // 路由跳转之前，关闭视频弹窗
      const params = {
        isVideo: false,
        name: '',
        status: '',
        videoLink: ''
      };
      store.commit('setData', { name: 'videoInfo', value: params });

      // 路由跳转改变 重置面板状态
      store.commit('setData', { name: 'boxStatus', value: true });
      next();
    } else {
      next('/login');
    }
  } else {
    next();
  }
});

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app');
